﻿using ALMDDD.Domain.Commands.SysUser;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;

namespace ALMDDD.Domain.Valications.SysUser
{
    /// <summary>
    /// 管理员验证基类
    /// </summary>
    public class SysUserValidation<T>: AbstractValidator<T> where T : SysUserCommand
    {
        /// <summary>
        /// 验证用户名
        /// </summary>
        protected void ValidateUserName()
        {
            RuleFor(c => c.UserName)
                .NotEmpty().WithMessage("姓名不能为空")
                .Length(1, 5).WithMessage("姓名在2~10个字符之间");
            
        }
        /// <summary>
        /// 验证邮箱
        /// </summary>
        protected void ValidateEmail()
        {
            RuleFor(c => c.Email)
                .EmailAddress().WithMessage("邮箱不正确");
        }
        /// <summary>
        /// 验证用户名
        /// </summary>
        protected void ValidUserId()
        {
            RuleFor(c => c.UserId)
                .NotEmpty().WithMessage("用户ID不为空!")
                .Length(1,20).WithMessage("用户名在1~20位!");
        }
        /// <summary>
        /// 验证用户名称
        /// </summary>
        protected void ValidUserName()
        {
            RuleFor(c => c.UserName)
                .NotEmpty().WithMessage("用户姓名不为空!")
                .Must(JudgeUserName)
                .WithMessage("用户名称不能为admin");
        }

        protected static bool JudgeUserName(string userName)
        {
            return userName != "admin";
        }

    }
}
